import React from 'react'
import axios from 'axios'

class App extends React.Component {
  constructor() {
    super()
    this.state = {
      data: []
    }
  }
  componentDidMount() {
    axios.get('http://localhost:5500/serve/data.json', {
      params: {
        id: '西安天气'
      }
    })
      .then(res => {
        this.setState({
          data: res.data
        })
        console.log(res);
      })
      .catch((e) => {
        console.log('获取数据失败');
        console.log(e)
      });
  }
  fn = () => {
    console.log(this.state.data)
  }
  render() {
    return <div>
      {
        this.state.data.map((item, index) => {
          return <p key={index}>
            {item.name}
          </p>
        })
      }
    </div>
  }
}
// axios.get('地址',{params:{id:'值'}}).then(res => {
//   console.log('成功'+res)
// }).catch(e=>{
//   console.log('请求失败')
// })

export default App